package utils;

import lombok.Getter;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DataSourceUtils {
    @Getter
    private static Connection connection;

    static {
        InputStream in = DataSourceUtils.class.getClassLoader().getResourceAsStream("datasource.properties");
        Properties properties = new Properties();
        try {
            properties.load(in);
            String className = properties.getProperty("driverClassName");
            String url = properties.getProperty("url");
            String username = properties.getProperty("username");
            String password = properties.getProperty("password");
            Class.forName(className);
            connection = DriverManager.getConnection(url, username, password);
        } catch (IOException | ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}

